package com.example.chatgpt000.controller;

import com.example.chatgpt000.service.OpenAiService;
import com.example.chatgpt000.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@RestController
@RequestMapping("/chat")
public class OpenAiController {
    @Autowired
    private OpenAiService service;

    @GetMapping
    public ModelAndView index() {
        ModelAndView modelAndView = new ModelAndView("index");
        return modelAndView;
    }

    @PostMapping("/chat1")
    public R index1(@RequestBody String question) {
        List answer = service.getAnswer(question);


        return R.ok(answer.get(0));
    }
}
